//--------------------------------------------------- // Purpose: Demonstrate file input/output // Author: John Gauch //--------------------------------------------------- #include #include using namespace std; int main() { // Open files ifstream din; din.open("infile.txt"); ofstream dout; dout.open("outfile.txt"); // Error checking if (din.fail()) cout << "Error not open input file\n"; else if (dout.fail()) cout << "Error not open output file\n"; else { // Loop reading and writing string str; while (din >> str) dout << str << " "; } // Close files din.close(); dout.close(); }